<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<base href="../../" />
		<script src="list.js"></script>
		<script src="page.js"></script>
		<link type="text/css" rel="stylesheet" href="page.css" />
	</head>
	<body>
		<h1>[name]</h1>
		<div>
			If you use just procedural geometries and don't load any textures, webpages should work
			straight from the file system, just double-click on HTML file in a file manager and it
			should appear working in the browser (you'll see <em>file:///yourFile.html</em> in the address bar).
		</div>

		<h2>Content loaded from external files</h2>
		<div>
			<p>
				If you load models or textures from external files, due to browsers' [link:http://en.wikipedia.org/wiki/Same_origin_policy same origin policy]
			 	security restrictions, loading from a file system will fail with a security exception.
		 	</p>

			<p>There are two ways to solve this:</p>

			<ol>
				<li>
					Change security for local files in a browser. This allows you to access your page as: <code>file:///yourFile.html</code>
				</li>
				<li>
					Run files from a local web server. This allows you to access your page as: <code>http://localhost/yourFile.html</code>
				</li>
			</ol>

			<p>
				If you use option 1, be aware that you may open yourself to some vulnerabilities if using
				the same browser for a regular web surfing. You may want to create a separate browser
				profile / shortcut used just for local development to be safe. Let's go over each option in turn.
			</p>
		</div>


		<h2>Run a local server</h2>
		<div>
			<p>
				Many programming languages have simple HTTP servers built in. They are not as full featured as
				production servers such as [link:https://www.apache.org/ Apache] or [link:https://nginx.org NGINX], however they should be sufficient for testing your
				three.js application.
			</p>

			<h3>Node.js server</h3>
			<div>
				<p>Node.js has a simple HTTP server package. To install:</p>
				<code>npm install http-server -g</code>

				<p>To run (from your local directory):</p>
				<code>http-server . -p 8000</code>
			</div>

			<h3>Python server</h3>
			<div>
				<p>
					If you have [link:http://python.org/ Python] installed, it should be enough to run this
					from a command line (from your working directory):
				</p>
				<code>
//Python 2.x
python -m SimpleHTTPServer

//Python 3.x
python -m http.server
				</code>

				<p>This will serve files from the current directory at localhost under port 8000, i.e in the address bar type:</p>

				<code>http://localhost:8000/</code>
			</div>

			<h3>Ruby server</h3>
			<div>
				<p>If you have Ruby installed, you can get the same result running this instead:</p>
				<code>
ruby -r webrick -e "s = WEBrick::HTTPServer.new(:Port => 8000, :DocumentRoot => Dir.pwd); trap('INT') { s.shutdown }; s.start"
				</code>
			</div>

			<h3>PHP server</h3>
			<div>
				<p>PHP also has a built-in web server, starting with php 5.4.0:</p>
				<code>php -S localhost:8000</code>
			</div>

			<h3>Lighttpd</h3>
			<div>
				<p>
					Lighttpd is a very lightweight general purpose webserver. We'll cover installing it on OSX with
					HomeBrew here. Unlike the other servers discussed here, lighttpd is a full fledged production
					ready server.
				</p>

				<ol>
					<li>
						Install it via homebrew
						<code>brew install lighttpd</code>
					</li>
					<li>
						Create a configuration file called lighttpd.conf in the directory where you want to run
						your webserver. There is a sample [link:http://redmine.lighttpd.net/projects/lighttpd/wiki/TutorialConfiguration here].
					 </li>
					<li>
						In the conf file, change the server.document-root to the directory you want to serve files from.
					</li>
					<li>
						Start it with
						<code>lighttpd -f lighttpd.conf</code>
					</li>
					<li>
						Navigate to http://localhost:3000/ and it will serve static files from the directory you
						chose.
					</li>
				</ol>
			</div>

		<h2>Change local files security policy</h2>
		<div>
			<h3>Safari</h3>
			<div>
				<p>
					Enable the develop menu using the preferences panel, under Advanced -&gt; "Show develop menu
					in menu bar".
				</p>

				<p>
					Then from the safari "Develop" menu, select "Disable local file restrictions", it is also
					worth noting safari has some odd behaviour with caches, so it is advisable to use the
					"Disable caches" option in the same menu; if you are editing &amp; debugging using safari.
				</p>
			</div>


			<h3>Chrome</h3>
			<div>
				<p>Close all running Chrome instances first. The important word here is 'all'.</p>

				<p>
					On Windows, you may check for Chrome instances using the Windows Task Manager.
					Alternatively, if you see a Chrome icon in the system tray, then you may open its context
					menu and click 'Exit'. This should close all Chrome instances.
				</p>

				<p>Then start the Chrome executable with a command line flag:</p>

				<code>chrome --allow-file-access-from-files</code>

				<p>
					On Windows, probably the easiest is probably to create a special shortcut icon which has
					added the flag given above (right-click on shortcut -&gt; properties -&gt; target).
				</p>

				<p>On Mac OSX, you can do this with</p>

				<code>open /Applications/Google\ Chrome.app --args --allow-file-access-from-files</code>
			</div>

			<h3>Firefox</h3>
			<div>
				<ol>
				<li>
					In the address bar, type <code>about:config</code>
				</li>
				<li>
					Find the <code>security.fileuri.strict_origin_policy</code> parameter
				</li>
				<li>
					Set it to <em>false</em>
				</li>
				</ol>
			</div>

		</div>

			<p>
				Other simple alternatives are [link:http://stackoverflow.com/q/12905426/24874 discussed here]
				on Stack Overflow.
			</p>
		</div>

	</body>
</html>
